from django.utils.deprecation import MiddlewareMixin
from django.http import JsonResponse
import logging

from django.core.exceptions import FieldError
logger = logging.getLogger("test")

class CustomResponseOuterLayerMiddleware(MiddlewareMixin):

    def process_exception(self, request, exception):
        if isinstance(exception, FieldError):
            logger.debug(exception)
            response = JsonResponse({
                "code": 500, 
                "msg": f"Internal Server Error {exception}",
                })
        else:
            response = JsonResponse({
                "code": 500, 
                "msg": f"Internal Server Error {exception}",
                })
        response.status_code = 200
        return response
    
        
        